/*
 * Class: FileReaderXMLHelper
 * Created by: Mary Joy Pascual
 * Date Created: 06/17/2014
 * Company: Netsuite
*/
package com.netsuite.helper;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
 

public class FileReaderXMLHelper {
	
	public static Map<String, String> stateMapperReader() throws ParserConfigurationException, SAXException, IOException{
		
		Map<String, String> titleMap = new HashMap<String, String>();
		File fXmlFile = new File("MapperConfig.xml");
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
		Document doc = dBuilder.parse(fXmlFile);
		doc.getDocumentElement().normalize();
		NodeList nList = doc.getElementsByTagName("field");
		for (int temp = 0; temp < nList.getLength(); temp++) {
			Node nNode = nList.item(temp);
			if (nNode.getNodeType() == Node.ELEMENT_NODE) {
				Element eElement = (Element) nNode;
				titleMap.put(eElement.getElementsByTagName("netsuite").item(0).getTextContent(),eElement.getElementsByTagName("csv").item(0).getTextContent());
			}
		}
		return titleMap;
		
	}

}
